<template>
  <div class="updata-gender">
      <van-picker
        show-toolbar
        :columns="columns"
        @cancel="$emit('close')"
        @confirm="onConfirm"
        :default-index="defaultIndex"
        @change="onGenderChange"
      />
  </div>
</template>
<script>
import { UserProfile } from '@/api/user.js'
export default {
  name: 'UpdataGender',
  props:{
    value:{
        type:Number,
        required:true
    }
  },
  components: { },
  directives: {  },
  data() {
    return {
       columns: ['男', '女'],
       defaultIndex:this.value
    };
  },

  mounted() {

  },

  methods: {
    onGenderChange(picker,value,index){
          this.defaultIndex=index
    },
    async onConfirm() {
          this.$toast.loading({
            message:'保存中',
            forbidClick:true
          })
            await UserProfile({
                gender:this.defaultIndex
            })
            this.$emit('input',this.defaultIndex)
            this.$toast.success('保存成功')
            //关闭弹窗
            this.$emit('close');
    },
  },
};
</script>

<style lang="less" scoped>

</style>
